<?php
class Book_model extends CI_Model{
	function __construct(){
		parent::__construct();
	}

    function getBookById($book_id){
        $this->db->where('book_id',$book_id);
        return $this->db->get('books')->result();
    }
    
    function getBooks($id) {
       //$this->db->select('id','name','author_id','author_name','price','image','parameter','summary','coin');
        $this->db->where('id',$id);
        return $this->db->get('books')->result();
    }

    function insertBook($data){
        if(empty($data['book_id'])){
            exit;
        }
        $book_id = $data['book_id'];
        $book_info = $this->getBookById($book_id);
        if(empty($book_info)){
            $this->db->insert('books',$data);
            return $this->db->insert_id();
        }else{
            return $book_info[0]->id;
        }
    }
}
?>